import { registerMicroApps, start, initGlobalState } from "qiankun";
import eventBus from "./eventBus";

// const state = {
//   name: "wifi",
// }
// // 初始化 state
// const actions = initGlobalState(state);

// actions.onGlobalStateChange((state, prev) => {
//   // state: 变更后的状态; prev 变更前的状态
//   console.log(state, prev);
// });
// actions.setGlobalState(state);

// actions.offGlobalStateChange();

registerMicroApps([
  // 当匹配到 activeRule 的时候，请求获取 entry 资源，渲染到 container 中。
  {
    name: "webpack-vue", //子应用名称
    entry: "//localhost:7001", //子应用入口（html入口）
    container: "#container", //子应用挂载容器
    activeRule: "/webpack-vue", //子应用路由匹配规则
    // props: {
    //   propsData: 'propsData'
    // }
  },
  {
    name: "vite-vue",
    entry: "//localhost:7002",
    container: "#container",
    activeRule: "/vite-vue",
  },
  {
    name: "sub-vanilla",
    entry: "//localhost:7003",
    container: "#container",
    activeRule: "/sub-vanilla",
  },
]);

(window as any).customEventBus = eventBus;

(window as any).customEventBus.on('sub-webpack-vue', (msg: any) => {
  console.log('主应用收到子应用消息:', msg);
});

// start({
//   sandbox: {
//     // experimentalStyleIsolation: true,
//   }
// });
